package session.servlet;

import session.entity.Cake;
import session.entity.CakeDB;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "CartServelt", value = "/cake-cart")
public class CartServelt extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        HttpSession session = request.getSession();
        List<Cake> cart = (List<Cake>) session.getAttribute("cart");
        if(cart == null || cart.isEmpty()){
            response.sendRedirect("/cake-list");
        }else {
            PrintWriter w = response.getWriter();
            for(Cake cake : cart){
                w.write(cake.getName()+"<br>");
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
